﻿#include "BugBagMaggot.h"
#include "../../../Shared/Globals.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../Settings.h"
#include "../../../Shared/ServerPackets.h"
#include "../DelayedAction.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool BugBagMaggot::getCanMove() const
    {
        return false;
    }

    BugBagMaggot::BugBagMaggot(MonsterInfo *info) : MonsterObject(info)
    {
        setDirection(MirDirection::Up);
    }

    void BugBagMaggot::Turn(MirDirection dir)
    {
    }

    bool BugBagMaggot::Walk(MirDirection dir)
    {
        return false;
    }

    bool BugBagMaggot::InAttackRange()
    {
        return getCurrentMap() == getTarget()->getCurrentMap() && Functions::InRange(getCurrentLocation(), getTarget()->getCurrentLocation(), Globals::DataRange);
    }

    void BugBagMaggot::Attack()
    {
        ShockTime = 0;

        if (!getTarget()->IsAttackTarget(this))
        {
            setTarget(nullptr);
            return;
        }

        if (SlaveList.size() >= 20)
        {
            return;
        }

        MonsterObject *spawn = GetMonster(getEnvir()->GetMonsterInfo(Settings::BugBatName));

        if (spawn == nullptr)
        {
            return;
        }

        S::ObjectAttack *tempVar = new S::ObjectAttack();
        tempVar->ObjectID = ObjectID;
        tempVar->Direction = getDirection();
        tempVar->Location = getCurrentLocation();
        Broadcast(tempVar);

        ActionTime = getEnvir()->getTime() + 300;
        AttackTime = getEnvir()->getTime() + 3000;

        spawn->setTarget(getTarget());
        spawn->ActionTime = getEnvir()->getTime() + 1000;
        DelayedAction tempVar2(DelayedType::Spawn, getEnvir()->getTime() + 500, {spawn, getCurrentLocation(), this});
        getCurrentMap()->ActionList.push_back(&tempVar2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void BugBagMaggot::ProcessRoam()
    {
    }
}
